# Maintainer: Luca Weiss <luca@lucaweiss.eu>

_flavor="postmarketos-qcom-sc7280"
pkgname=linux-$_flavor
pkgver=6.12.0
pkgrel=1
pkgdesc="Mainline Kernel fork for SC7280/SM7325/QCM6490 devices"
arch="aarch64"
_carch="arm64"
url="https://github.com/sc7280-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	"
makedepends="bash bison findutils flex installkernel openssl-dev perl python3"

_repo="linux"
_config="config-$_flavor.$arch"
_tag="v$pkgver-sc7280"

# Source
source="
	https://github.com/sc7280-mainline/$_repo/archive/refs/tags/$_tag/$_repo-$_tag.tar.gz
	$_config
"
builddir="$srcdir/$_repo-$pkgver-sc7280"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$arch" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
		"$pkgdir/boot/vmlinuz"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
ce44a305f7ddd069dd834af453f9d3d7913ee81f197e0f36ed6f3599d4dafda8c1f334c2627f842a159da581f8317ceff064be8c482363106d06ce7f4d6d0752  linux-v6.12.0-sc7280.tar.gz
c33a77ca50ef8406b7222fcf931fe7e3e0f0d3e9672fdd87d2c2cd1c0698ede1662ea6913dd351ad24d9e98caf9ae02dc004df92bb909ec36074dc5f888ec952  config-postmarketos-qcom-sc7280.aarch64
"
